package com.wkh.project.customer.controller;

import com.wkh.project.common.result.Result;
import com.wkh.project.common.util.AuthContextHolder;
import com.wkh.project.customer.service.CustomerService;
import com.wkh.project.model.form.customer.UpdateCustomerInfoForm;
import com.wkh.project.model.form.customer.UpdateWxPhoneForm;
import com.wkh.project.model.vo.customer.CustomerInfoVo;
import com.wkh.project.model.vo.customer.CustomerLoginVo;
import com.wkh.project.service.annotation.LoginCheck;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@Slf4j
@Tag(name = "客户API接口管理")
@RestController
@RequestMapping("/customer")
@SuppressWarnings({"unchecked", "rawtypes"})
public class CustomerController {
    @Resource
    private CustomerService customerService;

    @Operation(summary = "微信小程序授权登录接口")
    @GetMapping("/login/{code}")
    public Result<String> login(@PathVariable(value = "code") String code, HttpServletRequest request){
        return Result.ok(customerService.login(code,request));
    }

    @Operation(summary = "获取登录信息")
    @LoginCheck
    @GetMapping("/getCustomerLoginInfo")
    public Result<CustomerLoginVo> getCustomerLoginInfo(){
        //1.从ThreadLocal中获得用户id
        Long customerId = AuthContextHolder.getUserId();
        //2.调用service方法
        CustomerLoginVo customerLoginVo = customerService.getCustomerInfo(customerId);
        return Result.ok(customerLoginVo);
    }

    @Operation(summary = "更新用户微信手机号")
    @LoginCheck
    @PostMapping("/updateWxPhone")
    public Result updateWxPhone(@RequestBody UpdateWxPhoneForm updateWxPhoneForm) {
        updateWxPhoneForm.setCustomerId(AuthContextHolder.getUserId());
//        Boolean updated = customerService.updateWxPhoneNumber(updateWxPhoneForm);
        return Result.ok(true);
    }

    /*@Operation(summary = "更新客户基本信息")
    @PostMapping("/updateCustomerInfo")
    public Result<Boolean> updateCustomerInfo(@RequestBody UpdateCustomerInfoForm updateCustomerInfoForm) {
        return Result.ok(customerService.updateCustomerInfo(updateCustomerInfoForm));
    }*/
}

